package com.rest.demo.concurrent;

import com.rest.demo.functional.concurrent.ConcurrentUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author Administrator
 * @decription 两种传统创建线程的方式
 * @Date 2018-01-31 14:43
 */
public class TwoStyleDemo {

    public static void main(String[] args) {
        Thread thread = new Thread() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName());
            }
        };
        thread.start();

        Runnable task = () -> System.out.println(Thread.currentThread().getName());
        List<Thread> taskList = new ArrayList<Thread>();
        for (int i = 0; i < 10; i++) {
            taskList.add(new Thread(task));
        }
        ExecutorService executor = Executors.newFixedThreadPool(10);
        taskList.stream().forEach(t -> executor.submit(t));
        ConcurrentUtils.stop(executor);
    }
}
